Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: create local stores and UTS - WPB-12100 #2141

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from

Conversation

jullianm
Copy link
Contributor

@jullianm jullianm commented Nov 8, 2024

TaskWPB-12100 [iOS] Create remaining local stores and add UTs for all stores

Key points

This PR isolates tests for our storage layer (local stores) and revisits tests for all our existing repositories.
Missing local stores were also created so the storage logic could be moved out from related repositories.

BEFORE:

  • Local stores were indirectly tested through our repositories

AFTER:

  • Each local store is directly tested.
  • Mock local stores are injected into repositories, repositories tests were revisited consequently.

In addition:

  • Removes super.setUp() and super.tearDown() code from all tests
  • Ensures local stores know nothing about API objects (using model mappers)
  • Uses .mockID instances from WireTestingPackage
  • Harmonizes tests naming

Testing

  • Add dedicated tests for all local stores
  • Revisit repositories tests

Checklist

  • Title contains a reference JIRA issue number like [WPB-XXX].
  • Description is filled and free of optional paragraphs.
  • Adds/updates automated tests.

UI accessibility checklist

If your PR includes UI changes, please utilize this checklist:

  • Make sure you use the API for UI elements that support large fonts.
  • All colors are taken from WireDesign.ColorTheme or constructed using WireDesign.BaseColorPalette.
  • New UI elements have Accessibility strings for VoiceOver.

@echoes-hq echoes-hq bot added echoes: technical-roadmap Work contributing to the Technical Roadmap, to improve our velocity or reduce the technical debt. echoes/initiative: ios-sync-refactoring labels Nov 8, 2024
func storeConnection(
_ connectionPayload: Connection
_ connectionInfo: ConnectionInfo
Copy link
Contributor Author

@jullianm jullianm Nov 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll see changes like this in this PR: storage layer should not be aware of API objects so we create a domain model between repository and local store, here's the steps:

  1. Repo will fetch API model from remote.
  2. Repo will prepare data for the local store by mapping it to a domain model
  3. Repo will pass this model to the local store
  4. Local store will rely that model to manipulate (fetch, update, create) NSManagedObject

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So now, it looks like all NSManagedObjects or context are isolated to Local stores, right?
I wonder if they would be cases where we want to be more flexible : thinking about the save contexts strategy we discussed.

Or going even further isolate all this to a WireStorage package

Copy link
Contributor Author

@jullianm jullianm Nov 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes storage operations are isolated to the local stores.

Moving to a WireStorage package could make sense as it would be consistent with the approach we used in WireAPI that contains UsersAPI ConversationsAPI...

WireStorage could follow that approach with UsersLocalStore ConversationsLocalStore etc and later introduce a generic storage service that our stores would rely on to perform any kind of local operations, just like we did with APIService in WireAPI.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should consider this still an open topic as it has a lot of implications to the overall architecture that should be further investigated. Having said that, I think that for now it is fine to introduce such isolation since it's generally easier to remove abstractions that it is to put them in place.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johnxnguyen you mean the WireStorage move ?

Copy link
Contributor

github-actions bot commented Nov 8, 2024

Test Results

165 tests   165 ✅  7s ⏱️
 47 suites    0 💤
  1 files      0 ❌

Results for commit 3d9ee9d.

♻️ This comment has been updated with latest results.

)

static let conversationLabel2 = ConversationLabelInfo(
id: .mockID4,
Copy link
Contributor Author

@jullianm jullianm Nov 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

across tests we now use UUID helpers from WireTestingPackage

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we specifically need predefined ids or would it work to create random ids?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would work creating random ids, I figured it would be nice to harmonize the code by using our UUID helper across all tests

Copy link
Collaborator

@netbe netbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM;)

public let conversationID: UUID?
public let qualifiedConversationID: WireDataModel.QualifiedID?
public let lastUpdate: Date
public let status: WireDataModel.ZMConnectionStatus
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you thinking to eventually have a complete domain model by not using anything from WireDataModel?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it'd be nice to gradually move away from WireDataModel. Although a lot was factored out, we still rely a lot on it in our local stores typically using the extension helpers from the different moc. I feel like this is also related to the discussion we have regarding a WireStorage package (and the spike ticket), having a fully isolated storage layer that doesn't depend anymore on WireDataModel

Comment on lines 44 to 46
enum Error: Swift.Error {
case failedToStoreLabelLocally(UUID)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer to call the nested error Failure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in ff83af9

)

static let conversationLabel2 = ConversationLabelInfo(
id: .mockID4,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we specifically need predefined ids or would it work to create random ids?


static let lastEventIDUserDefaultsKey = "\(selfUserID.uuid.uuidString)_lastEventID"

nonisolated(unsafe) static let envelope1 = UpdateEventEnvelope(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is nonisolated(unsafe) needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed in ff83af9, add Sendable conformance to related value types

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
echoes/initiative: ios-sync-refactoring echoes: technical-roadmap Work contributing to the Technical Roadmap, to improve our velocity or reduce the technical debt.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants